package site.oldpei.manage.erupt.entity;

import lombok.*;
import site.oldpei.manage.erupt.service.VedioPlayService;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.RowOperation;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.sub_edit.AttachmentType;
import xyz.erupt.annotation.sub_field.sub_edit.BoolType;
import xyz.erupt.jpa.model.BaseModel;

import javax.persistence.*;
import java.util.List;

/*
 *	@Erupt注解修饰在类上，@EruptField注解修饰在字段上
 *	其他注解均为Jpa注解
 */
@EqualsAndHashCode(callSuper = true)
@Erupt(name = "视频信息",
        desc = "本地视频管理",
        //操作按钮
        rowOperation = {@RowOperation(
                title = "播放",
                code = "SINGLE",
                mode = RowOperation.Mode.SINGLE,
                operationHandler = VedioPlayService.class)}
)
@Table(name = "p_vedio_info")
@Entity
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class VedioInfo extends BaseModel {

    //番号
    @EruptField(
            views = @View(title = "番号"),
            edit = @Edit(title = "番号")
    )
    private String identificationCode;
    //标题
    @EruptField(
            views = @View(title = "标题"),
            edit = @Edit(title = "标题")
    )
    private String title;


    //评分
    @EruptField(
            views = @View(title = "评分"),
            edit = @Edit(title = "评分")
    )
    private String rating;


    //剧情
    @EruptField(
            views = @View(title = "剧情"),
            edit = @Edit(title = "剧情")
    )
    private String plot;

    //时长
    @EruptField(
            views = @View(title = "时长"),
            edit = @Edit(title = "时长")
    )
    private String runtime;


    //地区
    @EruptField(
            views = @View(title = "地区"),
            edit = @Edit(title = "地区")
    )
    private String country;


    //发布时间
    @EruptField(
            views = @View(title = "发布时间"),
            edit = @Edit(title = "发布时间")
    )
    private String premiered;

    //工作室
    @EruptField(
            views = @View(title = "工作室"),
            edit = @Edit(title = "工作室")
    )
    private String studio;
    //导演
    @EruptField(
            views = @View(title = "导演"),
            edit = @Edit(title = "导演")
    )
    private String director;

    @ManyToMany //演员
    @JoinTable(name = "p_vedio_actor_rel", //定义多对多中间表
            joinColumns = @JoinColumn(name = "vedio_id", referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn(name = "actor_id", referencedColumnName = "id"))
    @EruptField(
            edit = @Edit(
                    title = "演员",
                    type = EditType.TAB_TABLE_REFER
            )
    )
    List<ActorInfo> actors;

    @ManyToMany //视频类型
    @JoinTable(name = "p_vedio_genre_rel", //定义多对多中间表
            joinColumns = @JoinColumn(name = "vedio_id", referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn(name = "genre_id", referencedColumnName = "id"))
    @EruptField(
            edit = @Edit(
                    title = "视频类型",
                    type = EditType.TAB_TABLE_REFER
            )
    )
    List<VedioGenre> genres;

    @ManyToMany //视频标签
    @JoinTable(name = "p_vedio_tag_rel", //定义多对多中间表
            joinColumns = @JoinColumn(name = "vedio_id", referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn(name = "tag_id", referencedColumnName = "id"))
    @EruptField(
            edit = @Edit(
                    title = "视频标签",
                    type = EditType.TAB_TABLE_REFER
            )
    )
    List<VedioTag> tags;

    //本地路径
    @EruptField(
            views = @View(title = "本地路径"),
            edit = @Edit(title = "本地路径",
                    type = EditType.ATTACHMENT,
                    attachmentType = @AttachmentType)
    )
    private String filePath;
    //详情页
    @EruptField(
            views = @View(title = "详情页"),
            edit = @Edit(title = "详情页",
                    type = EditType.ATTACHMENT,
                    attachmentType = @AttachmentType)
    )
    private String fanart;
    //封面
    @EruptField(
            views = @View(title = "封面"),
            edit = @Edit(title = "封面", type = EditType.ATTACHMENT,
                    attachmentType = @AttachmentType)
    )
    private String poster;
    //是否自动
    @EruptField(
            views = @View(title = "是否自动"),
            edit = @Edit(
                    title = "是否自动",
                    boolType = @BoolType
            )
    )
    private boolean isAuto = false;
}
